<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 
        class MovieCollection extends Array {
            constructor(name, ...items) { // reset 获取对象字面量数组全部元素
                super(...items);// suprer 调用父类的构造函数  ...items不是reset是展开运算符
                this.name = name;
            }

            add(movie) {
                this.push(movie);
            }
            topRated(limit = 10) { // es6的给参数默认值
                return this.sort((a, b) => a.start - b.start).slice(0, limit)
            }


        }

        const moives = new MovieCollection('Wes\'s Fav Movies',
            { name: 'Bee Movie', start: 10 },
            { name: 'Good Movie', start: 1 },
            { name: 'Bad Movie', start: 7 },
            { name: 'Last Movie', start: 8 }
        )
        moives.add({ name: '战狼', start: 9 });
        console.log(moives.topRated(3))
    </script>
</body>

</html>